package io.renren.modules.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.shop.dao.ShopBrandDao;
import io.renren.modules.shop.entity.ShopBrandEntity;
import io.renren.modules.shop.service.ShopBrandService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 品牌业务层
 */
@Service
public class ShopBrandServiceImpl extends ServiceImpl<ShopBrandDao, ShopBrandEntity> implements ShopBrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //不存在 page
//        if(params!=null && !params.containsKey("page")){
//            params.put("page",1);
//        }
//
//        if(params!=null && !params.containsKey("limit")){
//            params.put("limit",10);
//        }

       // IPage<ShopBrandEntity> page = new Page<>();
       // page.setCurrent(params.get("page"));

        //封装好的获取对象的方式
        IPage<ShopBrandEntity> page = new Query<ShopBrandEntity>().getPage(params);

        //根据条件查询
        QueryWrapper<ShopBrandEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(params.containsKey("name"),"name",params.get("name"));

        //mybatis-plus提供了分页方法
        IPage<ShopBrandEntity> page1 = this.page(page,queryWrapper);



        return  new PageUtils(page1);
    }
}
